package com.starlinkdt.api.controller.admin.system;

import com.starlinkdt.common.annotation.Log;
import com.starlinkdt.common.core.controller.BaseController;
import com.starlinkdt.common.core.page.TableDataInfo;
import com.starlinkdt.common.domain.AjaxResult;
import com.starlinkdt.common.domain.system.dto.OaiPermDto;
import com.starlinkdt.common.domain.system.entity.OaiPerm;
import com.starlinkdt.common.enums.BusinessType;
import com.starlinkdt.common.utils.poi.ExcelUtil;
import com.starlinkdt.service.system.IOaiPermService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * OAI权限Controller
 *
 * @author asset
 */
@Api(tags = "OAI权限管理")
@RestController
@RequestMapping("/admin/openapi/permission")
public class OaiPermController extends BaseController
{
    @Autowired
    private IOaiPermService oaiPermService;

    /**
     * 查询OAI权限列表
     */
    @ApiOperation("OAI权限-列表")
    @PreAuthorize("@ss.hasPermi('openapi:permission:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaiPerm oaiPerm)
    {
        startPage();
        List<OaiPerm> list = oaiPermService.selectOaiPermList(oaiPerm);
        return getDataTable(list);
    }

    /**
     * 导出OAI权限列表
     */
    @ApiOperation("OAI权限-导出")
    @PreAuthorize("@ss.hasPermi('openapi:permission:export')")
    @Log(title = "OAI权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaiPerm oaiPerm)
    {
        List<OaiPerm> list = oaiPermService.selectOaiPermList(oaiPerm);
        ExcelUtil<OaiPerm> util = new ExcelUtil<OaiPerm>(OaiPerm.class);
        util.exportExcel(response, list, "OAI权限数据");
    }

    /**
     * 获取OAI权限详细信息
     */
    @ApiOperation("OAI权限-查询")
    @PreAuthorize("@ss.hasPermi('openapi:permission:query')")
    @GetMapping(value = "/{permBizNo}")
    public AjaxResult getInfo(@PathVariable("permBizNo") String permBizNo)
    {
        return success(oaiPermService.selectOaiPermByPermBizNo(permBizNo));
    }

    /**
     * 新增OAI权限
     */
    @ApiOperation("OAI权限-新增")
    @PreAuthorize("@ss.hasPermi('openapi:permission:add')")
    @Log(title = "OAI权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaiPermDto oaiPermDto)
    {
        return toAjax(oaiPermService.insertOaiPerm(oaiPermDto));
    }

    /**
     * 修改OAI权限
     */
    @ApiOperation("OAI权限-修改")
    @PreAuthorize("@ss.hasPermi('openapi:permission:edit')")
    @Log(title = "OAI权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaiPermDto oaiPermDto)
    {
        return toAjax(oaiPermService.updateOaiPermByPermBizNo(oaiPermDto));
    }

    /**
     * 启用OAI权限
     */
    @ApiOperation("OAI权限-启用")
    @PreAuthorize("@ss.hasPermi('openapi:permission:edit')")
    @Log(title = "OAI权限", businessType = BusinessType.UPDATE)
    @PutMapping("enable/{permBizNos}")
    public AjaxResult enable(@PathVariable String[] permBizNos)
    {
        return toAjax(oaiPermService.enableOaiPermByPermBizNos(permBizNos));
    }

    /**
     * 禁用OAI权限
     */
    @ApiOperation("OAI权限-禁用")
    @PreAuthorize("@ss.hasPermi('openapi:permission:edit')")
    @Log(title = "OAI权限", businessType = BusinessType.UPDATE)
    @PutMapping("disable/{permBizNos}")
    public AjaxResult disable(@PathVariable String[] permBizNos)
    {
        return toAjax(oaiPermService.disableOaiPermByPermBizNos(permBizNos));
    }

    /**
     * 删除OAI权限
     */
    @ApiOperation("OAI权限-删除")
    @PreAuthorize("@ss.hasPermi('openapi:permission:remove')")
    @Log(title = "OAI权限", businessType = BusinessType.DELETE)
    @DeleteMapping("/{permBizNos}")
    public AjaxResult remove(@PathVariable String[] permBizNos)
    {
        return toAjax(oaiPermService.deleteOaiPermByPermBizNos(permBizNos));
    }

}
